<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-3.1.1.js"/>"></script>

<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>病床管理</title>
<style type="text/css">
.cc_item {
	padding: 10px;
}
</style>
</head>
<body>
	<script type="text/javascript">
		$(function() {
			$('#cc_berthsearch').searchbox({
				searcher : function(value, name) {
					if (name == "病房名称") {
						$("#ccberthtab").datagrid({
							url : 'tocc_queryByWname',
							queryParams : {
								wname : value
							}
						});
					}else if (name == "病房科室") {
						$("#ccberthtab").datagrid({
							url : 'tocc_queryBydepartmentName',
							queryParams : {
								departmentName : value
							}
						});
					} else {
						$("#ccberthtab").datagrid({
							url : 'tocc_findByGename',
							queryParams : {
								gename : value
							}
						});
					}

				}
			});
			var berthid;
			$("#cc_addbp").linkbutton(
					{
						onClick : function(index, row) {
							var crow = $("#ccberthtab")
									.datagrid("getSelections");
							if (crow.length == 1) {
								if (crow[0].berthstate == '空') {
									var n = crow[0].wname;
									var m = crow[0].pofficesname;
									var y = crow[0].wmoney;
									var b = crow[0].bname;
									berthid = crow[0].berthno;
									$('#cc_in_berthwin').window(
											{
												'title' : m + n + "病房" + b
														+ "号床办理入住" + y + "每天"
											});
									$('#cc_in_berthwin').window("open");
								} else {
									$.messager.alert("提示",
											"这个床位已经有人入住了,无法再分配给其他人！");
								}

							} else {
								$.messager.alert("提示", "只能选择一条记录，您目前选择了"
										+ crow.length + "条!");
							}
						}
					});
			
			$("#cc_berthsave").linkbutton({
						onClick : function(index, row) {
							$("#cc_berthtrimform").form(
									'submit',{
										onSubmit : function() {
											//返回true提交表单，返回false则阻止表单提交
								             return $(this).form('validate');
										},
										success : function(data) {
											//JSON字符串两边需要添加小括号
											var json = eval("("+data+")");
											$.messager.alert("提示", json.reason);
											//关闭窗口
											$('#cc_berthtrimwin').window('close');
											//重新加载数据
											$("#ccberthtab").datagrid("reload");
											$(this).form("clear");
										}

									});
						}
					});
			var  shenpi_staffId = $("#tontyiStaffId").html();
			$("#cc_hpdoctorid").val(shenpi_staffId);
			$("#cc_berthtrim").linkbutton(
					{
						onClick : function(index, row) {
							var brows = $("#ccberthtab").datagrid("getSelections");
							if (brows.length == 1) {
								//wname pofficesname bname
								$("#cc_berthtrimwin").window({
									"title":
										brows[0].pofficesname
										+brows[0].wname
										+"病房"+brows[0].bname+"号床位调整"
								});
								$("#cc_berthtrimwin").window("open");
								$("#oldberth_id").textbox("setText",brows[0].berthno);
								$("#oldberth_id").textbox("setValue",brows[0].berthno);
								$("#oldberth_id").textbox("readonly",true);
								$("#thandleid").val(shenpi_staffId);
								
								if (brows[0].berthstate == '空') {
									//tocc_querynotnullpaberthid
									$("#cc_patient").show();
									$("#ccberth").hide();
									$("#trpatientid").combogrid({
										url: 'tocc_querynotnullpaberthid'
									});
									
								}else{
									var v='空';
									$("#ccberth").show();
									$("#cc_patient").hide();
									$("#newberthid").combogrid({
										url: 'tocc_findByberthstate',
										queryParams: {
											state: v
							    		}
									});
								}
								
							} else {
								$.messager.alert("提示", "只能选择一条记录，您目前选择了"
										+ brows.length + "条!");
							}
						}
					});
			//办理入住
			$("#cc_savebpatient").linkbutton(
					{
						
						onClick : function(index, row) {
							
							var cbrows = $("#cc_add_wberthtab").datagrid("getSelections");
							if (cbrows.length == 1) {
								
								if(berthid!=null){
									var pid = cbrows[0].patientid;
									var bid = berthid;
									$("#b_id").val(bid);
									$("#p_id").val(pid);
									$("#cc_berthp").form('submit', {
										onSubmit : function(){
										},
										success : function(data) {
											//JSON字符串两边需要添加小括号
											var json = eval("(" + data + ")");
											$.messager.alert("提示", json.reason);
											//关闭窗口
											$('#cc_in_berthwin').window('close');
											//重新加载数据
											$("#addwberthtab").datagrid("reload");
											$("#ccberthtab").datagrid("reload");
											$(this).form("clear");
										}
									
									});
								}
							} else {
								$.messager.alert("提示", "只能选择一条记录，您目前选择了"
										+ cbrows.length + "条!");
							}
						}
					});
			$("#cc_berthcancel").linkbutton({
				onClick : function() {
					$('#cc_berthtrimwin').window('close');
					//重新加载数据
					$("#ccberthtab").datagrid("reload");
					$("#cc_berthtrimform").form("clear");
				}
			});
			$("#cc_queryAllberth").linkbutton({
				onClick : function() {
					var v='空';
					$("#ccberthtab").datagrid({
						url : 'tocc_findByberthstate',
						queryParams: {
							state: v
			    		}
					});

				}
			});
			$("#cc_notnullberth").linkbutton({
				onClick : function() {
					var v='已住人';
					$("#ccberthtab").datagrid({
						url : 'tocc_findByberthstate',
						queryParams: {
							state: v
			    		}
					});

				}
			});
			$("#cc_berth_ref").linkbutton({
				onClick : function() {
					$("#ccberthtab").datagrid({
						url : 'tocc_queryALLberth'
					});
				}
			});
			$("#cc_bpp_ref").linkbutton({
				onClick : function() {

					$("#addwberthtab").datagrid({
						url : 'tocc_querynullpaberthid'
					});
					
				}
			});
		});
	</script>
	<div style="display: none">
		<input id="cc_hpdoctorid" name="hpdoctorid" class="easyui-textbox"
			>
	</div>
	<table id="ccberthtab" class="easyui-datagrid"
		data-options="
							fitColumns:true,
							fit:true,
							striped:true,
							rownumbers: true,
						    url: 'tocc_queryALLberth',
							border:false ,
							pagination:true,
							pageSize: 16,
							pageList:[16,32,64,128],
							toolbar: '#cc_berth_btn'
						">
		<thead>
			<tr>
				<th data-options="field:'berthno',width:'6%',checkbox:true">床位编号</th>
				<th data-options="field:'bname',width:'10%'">床位号</th>
				<th data-options="field:'pname', width:'10%'">病人姓名</th>
				<th data-options="field:'gename', width:'15%'">病房类别</th>
				<th data-options="field:'wname', width:'15%'">病房名称</th>
				<th data-options="field:'pofficesname', width:'10%'">所属科室</th>
				<th data-options="field:'berthstate', width:'10%'">床位状态</th>
				<th data-options="field:'address', width:'17%'">地址</th>
				<th data-options="field:'wmoney', width:'10%'">日消费</th>
			</tr>
		</thead>
	</table>

	<div id="cc_berth_btn">
		<a id="cc_queryAllberth" class="easyui-linkbutton"
			data-options="iconCls:'icon-suoyou',plain:true">显示空床位</a>
			<a id="cc_notnullberth" class="easyui-linkbutton"
			data-options="iconCls:'icon-suoyou',plain:true">显示已住床位</a> <a
			id="cc_addbp" class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">登记入住</a>
			<a id="cc_berthtrim" class="easyui-linkbutton"
			data-options="iconCls:'icon-tiaozheng',plain:true">床位调整</a>
			<a id="cc_berth_ref" class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a><input
			id="cc_berthsearch" class="easyui-searchbox"
			data-options="menu:'#cc_berthee',width:220,prompt:'请输入你要查找的内容'">
	</div>
	<div id="cc_berthee" style="width: 90px">
		<div date-options="name:'name'">病房科室</div>
		<div date-options="name:'name'">病房类别</div>
		<div date-options="name:'name'">病房名称</div>
	</div>


	<div>
		<div id="cc_in_berthwin" class="easyui-window"
			style="padding: 0px; line-height: 150%;background: rgb(236,243,255);"
			data-options="
			iconCls:'icon-banliyewu',
		     width: 500,
		     height: 300,
		      modal:true,
		     closed: true
			">
			<table id="cc_add_wberthtab" class="easyui-datagrid"
				data-options="
							fitColumns:true,
							fit:true,
							url:'tocc_querynullpaberthid',
							rownumbers: true,
							toolbar: '#cc_saveberthpatient',
							pagination:true,
							pageSize: 7,
							pageList:[7,14,28,56],
							border:false 
						">
				<thead>
					<tr>
						<th data-options="field:'patientid',width:'6%',checkbox:true">住院号</th>
						<th data-options="field:'icid', width:'22%'">医疗卡编号</th>
						<th data-options="field:'pname',width:'18%'">病人姓名</th>
						<th data-options="field:'psex',width:'12%'">性别</th>
						<th data-options="field:'staffName', width:'18%'">主治医生</th>
						<th data-options="field:'departmentName', width:'24%'">所属科室</th>
					</tr>
				</thead>
			</table>
		</div>
		
	</div>
	<div id="cc_saveberthpatient" width="100%">
			<a id="cc_savebpatient" class="easyui-linkbutton"
				data-options="iconCls:'icon-add',plain:true">办理入住</a><a
				id="cc_bpp_ref" class="easyui-linkbutton"
				data-options="iconCls:'icon-reload',plain:true">刷新</a>
	</div>
	<div style="display: none;">
		<form id="cc_berthp" action="addberthp" method="post">
			<input id="b_id" name="bertnid"> <input id="p_id"
				name="patientid">
		</form>
	</div>

	<div id="cc_berthtrimwin" class="easyui-window"
			style="padding:10px;line-height: 150%;background: rgb(236,243,255);"
			data-options="
			iconCls:'icon-banliyewu',
		     width: 400,
		     height: 180,
		      modal:true,
		     closed: true,
		     title:'床位调整'
			">
			<form id="cc_berthtrimform" action="cc_addtrim" method="post">
				<div style="display: none">
						<input id="thandleid" name="thandleid">
				</div>
				<div class="cc_item">
						<input id="oldberth_id" name="thisbid" class="easyui-textbox"
							data-options="label: '此床位编号:',labelAlign:'right', width: 200">
				</div>
				<div class="cc_item">
						
						<input id="ttremarks" name="ttremarks" class="easyui-textbox"
							data-options="label: '调整说明:',labelAlign:'right',
							required: true,
     						missingMessage: '调整说明不能为空',
     						 width: 300">
			
				</div>
			<div id="ccberth" class="cc_item cc_dis" >
				<select id="newberthid" name="trimbid"  class="easyui-combogrid" data-options="
							labelAlign:'right', width: 300,
							label:'调整的床位:',
							panelHeight: 'auto',
							panelWidth: '377',
							idField: 'berthno',
							textField: 'bname',
							pagination:true,
							pageSize: 4,
							pageList:[4,8,16,32],
							columns: [[
								{field: 'berthno', title: '床位编号', width: 60},
								{field: 'bname', title: '床位号', width: 64},
								{field: 'wname', title: '病房名称', width: 60},
								{field: 'gename', title: '病房类别', width: 60},
								{field: 'wmoney', title: '日消费', width: 40},
								{field: 'address', title: '地址', width: 80},
								
							]]
						"></select>
				</div>
				<div id="cc_patient" class="cc_item cc_dis">
						<select id="trpatientid" name="trimpbid"  class="easyui-combogrid" data-options="
							labelAlign:'right', width: 300,
							label:'变更的患者:',
							panelHeight: 'auto',
							panelWidth: '398',
							idField: 'berthid',
							textField: 'pname',
							pagination:true,
							pageSize: 4,
							pageList:[4,8,16,32],
							columns: [[
								{field: 'berthid', title: '床位编号', width: 60},
								{field: 'bname', title: '床位号', width: 65},
								{field: 'patientid', title: '病人编号', width: 60},
								{field: 'pname', title: '病人姓名', width: 60},
								{field: 'psex', title: '性别', width: 30},
								{field: 'wmoney', title: '日消费', width: 40},
								{field: 'address', title: '地址', width: 80},
								
							]]
						"></select>
				
				</div>
				<div style="margin-left:20%;padding-top:4px">
						<a id="cc_berthsave"  class="easyui-linkbutton" data-options="iconCls:'icon-baocun'">确定</a>
						 <a id="cc_berthcancel" style="margin-left:40px" class="easyui-linkbutton" data-options="iconCls:'icon-chexiao'">取消</a>
					</div>
			</form>
				
	</div>

</body>
</html>